const arr = [1, -2, 3, 0, 5, -2, 6, -1];

function getMax(arr) {
  let sum = arr[0],
      pre = 0,
      startI = 0,
      endI = 0,
      cStartI = 0;
  for (let [index, num] of arr.entries()) {
    if (pre > 0) {
      pre += num
    } else {
      pre = num;
      endI = index - 1
      cStartI = index;
    }
    if (sum < pre) {
      sum =  pre;
      startI = cStartI;
      endI = index;
    }
  }
  console.log(sum);
  console.log(arr.slice(startI, endI + 1));
}
getMax(arr);

